<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 3,0,1 metric. 
Algebra(3,0,1,()=>{ 
    
  // Specify a point directly (trivectors specified with overloaded e-notation.)
  var point = (x,y,z)=>1e123-x*1e012+y*1e013+z*1e023;
  
  // Lines can be defined using plucker coordinates
  var line = (px,py,pz,dx,dy,dz)=>px*1e01+py&1e02+pz*1e03+dx*1e12+dy*1e13+dz*1e23;

  // Planes can be defined directly using e0,e1,e2,e3
  var plane = (a,b,c,d)=>d*1e0+a*1e1+b*1e2+c*1e3;
  
  // Useful distances
  var dist_pp = (P1,P2)=>(P1.Normalized&P2.Normalized).Length,    // point to point
      dist_pP = (P,p)=>(P.Normalized&p.Normalized).Length,        // point to plane
      dist_ll = (l1,l2)=>(!(l1.Normalized*l2.Normalized)).Length; // line to line
  
  // Useful angles
  var angle_pp = (p1,p2)=>Math.acos(p1.Normalized<<p2.Normalized)*180/Math.PI, // Angle between planes
      angle_ll = (l1,l2)=>Math.acos(l1.Normalized<<l2.Normalized)*180/Math.PI; // Angle between lines 
  
  // Create 5 points.
  var A=point(0,-1,0), B=point(1,1,-1), C=point(-1,1,-1), D=point(1,1,1), E=point(-1,1,1), 
  
  // Our ground plane
      a=B&C&D,
  
  // Our camera position and orientation
      camera=0e0;
  
  // Graph the 3D items
  document.body.appendChild(this.graph(()=>{
    var time=performance.now()/4000;    
    A=point(0,Math.sin(time*4),0);
    camera.set(Math.cos(time)+Math.sin(time)*1e13);                      // rotate around Y 
    return [0xddaaff,[A,B,C],                                            // graph on face
            0xAA88FF,[A,B],[A,C],[A,D],[B,C],[B,D],[C,E],[A,E],[E,D],    // graph all edges
            0x444444,A,"A",B,"B",C,"C",D,"D",E,"E",                      // graph all vertices
            0xFF8888,[A,E],dist_pp(A,E).toFixed(2),                      // distance A to E
            0x8888FF,[A,B+E],dist_pP(A,a).toFixed(2),                    // distance A to a
            0x44aa44,C+E,dist_ll(C&E,D&B).toFixed(2),                    // distance CE to DB
            0x44aaff,[A+D+E,B+C+5*D+5*E,D+E],(angle_pp(A&E&D,a).toFixed(2))+"°",   // angle planes.
            0xff44ff,[A,2*A+D,2*A+B],(angle_ll(A&D,B&A).toFixed(2))+"°"
           ];
  },{animate:true,camera})); 
  
});
</SCRIPT></BODY>